#pragma once

#ifdef __QT5_TARGET

#include <QtCore\QEvent>
#include <QtCore\QList>
#include <QtCore\QTime>
#include <QtWidgets\QMenu>
#include <QtWidgets\QTableView>

#else

#include <QTableView>
#include <QList>
#include <QTime>
#include <QEvent>
#include <QMenu>

#endif

#include "ScheduleTableModel.h"
#include "SchedulerDelegate.h"

enum Division{fifteen,thirty,hour,twohours};

class ScheduleTableView :
	public QTableView
{
	Q_OBJECT
	public slots:
		
		
		//void setLabel(int row, int column);
		void jumpToMorning();
		void jumpToAfternoon();
		//void jumpToSiesta();
		//void jumpToNight();
		void doShowSiesta(int state);
		void doShowNight(int state);
		void setFifteenMinDiv(bool checked);
		void setThirtyMinDiv(bool checked);
		void setOneHourDiv(bool checked);
		void setTwoHoursDiv(bool checked);
		void setColumnWidth(int width);
		void setRowHeight(int height);
		void merge();
		void unMerge();
		void scrollToCurrentTime();
		void setRowSpans();
		void handleDoubleClick(const QModelIndex& index);
		void handleMousePress(const QModelIndex& index);
		
		//void jumpToCurrentTime();	
public:
	void hideSiesta();
	void hideNight();
	void showSiesta();
	void showNight();
	ScheduleTableView(QWidget* parent=0);
	~ScheduleTableView(void);
	void setStartMorningIndex(int index);
	void setEndMorningIndex(int index);
	void setStartAfterNoonIndex(int index);
	void setEndAfterNoonIndex(int index);
	void setEndOfNightIndex(int index);
	void setModel(ScheduleTableModel* m);
	//void showSiesta(bool show);
	//void showNight(bool show);
	//void initialize(korlapAdmin_model* model,QLocale* locale);
	//void setModel(korlapAdmin_model* model);
	//void brushTable();
	void brushFraction(int begin, int end);
	void deleteSchedules();
protected slots:
	void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);	
	//void setMorningBegin(int i);
	//void setMorningEnd(int i);
	//void setNightBegin(int i);
	//void setNightEnd(int i);
	//void setSiestaTime(int i);
	/*
	QPair<QDateTime*,QDateTime*>* getWeekRange();
	QTableWidgetItem* morningItem();
	QTableWidgetItem* afternoonItem();
	QTableWidgetItem* siestaItem();
	QTableWidgetItem* nightItem();
	*/
	void editorClosed(QWidget* editor, QAbstractItemDelegate::EndEditHint hint = QAbstractItemDelegate::NoHint);
protected:
	//void mouseReleaseEvent(QMouseEvent* event);
	void keyPressEvent(QKeyEvent* event);
	void leaveEvent(QEvent * event);
private:
	void expandRows();
	QList<QAction*> menuActions;
	void setupMenu();
	Schedule* getSelectedSchedule();
	QList<Schedule*> getSelectedSchedules();
	void doDelete(Schedule *s);
	QMenu* menu;
	QList<Division> rowDivisions;
	int beginMorningIndex;
	int endMorningIndex;
	int beginAfterNoonIndex;
	int endAfterNoonIndex;
	int endNightIndex;
	ScheduleTableView* nextWeek;
	ScheduleTableView* prevWeek;
	bool eventFilter(QObject*,QEvent*);
	Division div;
	QPair<QDateTime*,QDateTime*> selectionBuffer;
	ScheduleTableModel* tableModel;
	/*
	int beginningOfMorningShift;
	int endOfMorningShift;
	int beginningOfNightShift;
	int endOfNightShift;
	int siestaTime;
	*/
	bool siesta;
	bool night;
	/*
	enum Shift {MORNING,SIESTA,AFTERNOON,NIGHT};
	Shift currentShift;
	korlapAdmin_model* model;
	QLocale* locale;
	QPair<QDateTime*,QDateTime*>* weekRange;
	*/
};
